/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.tree;

import org.rails.extjs.javascript.Function;


public class TreeNode extends Node {
	
	public TreeNode(){
		super();
	}
	
	public TreeNode(String text,String icon,Boolean leaf) {
		super();
		setText(text);
		setIcon(icon);
		setLeaf(leaf);
	}
	
	public TreeNode(String id,String text,String icon,Boolean leaf) {
		super(id);
		setText(text);
		setIcon(icon);
		setLeaf(leaf);
	}
	
	public void setAllowChildren(Boolean allowChildren){
		addOption("allowChildren", allowChildren);
	}
	
	public Boolean isAllowChildren(){
		return getBoolean("allowChildren",true);
	}
	
	public void setAllowDrag(Boolean allowDrag){
		addOption("allowDrag", allowDrag);
	}
	
	public Boolean isAllowDrag(){
		return getBoolean("allowDrag",true);
	}
	
	public void setAllowDrop(Boolean allowDrop){
		addOption("allowDrop", allowDrop);
	}
	
	public Boolean isAllowDrop(){
		return getBoolean("allowDrop",true);
	}
	
	public void setChecked(Boolean checked){
		addOption("checked", checked);
	}

	public Boolean isChecked(){
		return getBoolean("checked",false);
	}
	
	public void setClassName(String cls){
		addOption("cls", cls);
	}
	
	public String getClassName(){
		return getString("cls","");
	}
	
	public void setDisabled(Boolean disabled){
		addOption("disabled", disabled);
	}
	
	public Boolean isDisabled(){
		return getBoolean("disabled",false);
	}
	
	public void setDraggable(Boolean draggable){
		addOption("draggable", draggable);
	}
	
	public Boolean isDraggable(){
		return getBoolean("draggable",false);
	}
	
	public void setEditable(Boolean editable){
		addOption("editable", editable);
	}
	
	public Boolean isEditable(){
		return getBoolean("editable",true);
	}
	
	public void setExpandable(Boolean expandable){
		addOption("expandable", expandable);
	}
	
	public Boolean isExpandable(){
		return getBoolean("expandable",true);
	}
	
	public void setExpanded(Boolean expanded){
		addOption("expanded", expanded);
	}
	
	public Boolean isExpanded(){
		return getBoolean("expanded", true);
	}
	
	public void setHidden(Boolean hidden){
		addOption("hidden", hidden);
	}
	
	public Boolean isHidden(){
		return getBoolean("hidden",false);
	}
	
	public void setHref(String href){
		addOption("href", href);
	}
	
	public String getHref(){
		return getString("href","#");
	}
	
	public void setHrefTarget(String hrefTarget){
		addOption("hrefTarget", hrefTarget);
	}
	
	public String getHrefTarget(){
		return getString("hrefTarget","");
	}
	
	public void setIcon(String icon){
		addOption("icon", icon);
	}
	
	public String getIcon(){
		return getString("icon","");
	}
	
	public void setIconCls(String iconCls){
		addOption("iconCls", iconCls);
	}
	
	public String getIconCls(){
		return getString("iconCls","");
	}
	
	public void setTarget(Boolean isTarget){
		addOption("isTarget", isTarget);
	}
	
	public Boolean isTarget(){
		return getBoolean("isTarget", true);
	}
	
	public void setQtip(String qtip){
		addOption("qtip", qtip);
	}
	
	public String getQtip(){
		return getString("qtip","");
	}
	
	public void setQtipCfg(String qtipCfg){
		addOption("qtipCfg", qtipCfg);
	}
	
	public String getQtipCfg(){
		return getString("qtipCfg","");
	}
	
	public void setSingleClickExpand(Boolean singleClickExpand){
		addOption("singleClickExpand", singleClickExpand);
	}
	
	public Boolean isSingleClickExpand(){
		return getBoolean("singleClickExpand",true);
	}
	
	public void setText(String text){
		addOption("text", text);
	}
	
	public String getText(){
		return getString("text","");
	}
	
	public void setUiProvider(Function uiProvider){
		addOption("uiProvider", uiProvider);
	}
	
	@Override
	public String getScript() {
		createItems();
		script = new StringBuffer("");
//		script.append("new Ext.tree.TreeNode(");
		script.append(createOptions());
//		script.append(")");
		return script.toString();
	}

}
